<?php

App::uses('AppController', 'Controller');

/**
 * Materias Controller
 *
 * @property Materia $Materia
 */
class AlumnosController extends AppController
{

    public $uses = array(
        'Alumno',
        'AlumnosParalelo',
        'Nivele',
        'AlumnosParciale',
        'Paralelo',
        'User',
        'AlumnosPlanespago',
        'Planespago',
        'Pago',
        'AlumnosPago',
        'Gestione',
        'Materia',
        'Tiposparciale',
        'Ciclo',
        'Parciale',
        'Factura',
        'Parametrosfactura'
        );

    public $layout = 'colegio';
    public $components = array('Fechasconvert', 'Codigocontrol','Montoliteral');

    public function beforeFilter()
    {
        parent::beforeFilter();
        $this->Auth->allow('*');
    }

    public function index()
    {
        $alumnos = $this->Alumno->find('all', array('recursive' => -1));
        $this->set(compact('alumnos'));
    }

    public function nuevo()
    {
        $gestion = date('Y');
        $dcn = $this->Nivele->find('list', array(
            'conditions' => array('Nivele.gestion' => $gestion),
            'fields' => array('Nivele.id', 'Nivele.nombre'),
            'order' => array('Nivele.orden ASC')));
        $planes = $this->Planespago->find('list', array('fields' => array('Planespago.id', 'Planespago.nombre'), 'order' => array('Planespago.nombre ASC')));
        $gestiones = $this->Gestione->find('list', array('fields' => array('Gestione.nombre', 'Gestione.nombre'), 'order' => array('Gestione.nombre ASC')));

        if (!empty($this->request->data))
        {
            $nombrecompleto = $this->request->data['Alumno']['ap_paterno'] . ' ' . $this->request->data['Alumno']['ap_materno'] . ' ' . $this->request->data['Alumno']['nombre'];
            $fechaAlumno = $this->request->data['Alumno']['fecha_nacimiento'];
            $fechaNacimiento = $this->Fechasconvert->doCambiaFormato($fechaAlumno);
            $fechaPass = $this->Fechasconvert->doFechaPass($fechaAlumno);
            
            $nombreAlumno = $this->request->data['Alumno']['nombre'];
            
            $usuario =  $this->Fechasconvert->doUsuarioPass($nombreAlumno);
            $nombreUsuario = strtolower($usuario);
            
            $this->request->data['Alumno']['fecha_nacimiento'] = $fechaNacimiento;

            if ($this->Alumno->save($this->request->data['Alumno']))
            {
                $a = 1;
            }
            else
            {
                $a = 0;
            }
            if ($a)
            {
                $gestion = date('Y');
                $ultimoAlumno = $this->Alumno->getLastInsertID();

                $this->request->data['AlumnosPlanespago']['alumno_id'] = $ultimoAlumno;
                $this->AlumnosPlanespago->create();

                if ($this->AlumnosPlanespago->save($this->request->data['AlumnosPlanespago']))
                {
                    $aa = 1;
                }
                else
                {
                    $aa = 0;
                }
                if ($aa)
                {
                    

                    $this->request->data['AlumnosParalelo']['alumno_id'] = $ultimoAlumno;
                    $this->request->data['AlumnosParalelo']['gestion'] = $gestion;
                    $this->request->data['AlumnosParalelo']['estado_id'] = 1;

                    $this->AlumnosParalelo->create();

                    if ($this->AlumnosParalelo->save($this->request->data['AlumnosParalelo']))
                    {
                        $ab = 1;
                    }
                    else
                    {
                        $ab = 0;
                    }
                    if ($ab)
                    {
                        $this->request->data = "";
                        $this->request->data['Users']['username'] = $nombreUsuario;
                        $this->request->data['Users']['password'] = $fechaPass;
                        $this->request->data['Users']['alumno_id'] = $ultimoAlumno;
                        $this->request->data['Users']['group_id'] = 3;

                        if ($this->User->save($this->request->data['Users']))
                        {
                            $this->Session->setFlash(__("Alumno guardado!!! <br/> El usuario generado para el alumno $nombrecompleto es: <br/>
                                        USUARIO: '$nombreUsuario'<br/>
                                        PASSWORD:'$fechaPass'

                                         "), 
                                        'msgbueno');
                            $this->redirect(array('action' => 'index'));
                        }else {
                                    $this->Session->setFlash('Alumno NO guardado!!!', 'msgerror');
                                    $this->redirect(array('action' => 'index'));
                                }
                }else{
                                $this->Session->setFlash('Alumno NO guardado!!!', 'msgerror');
                                $this->redirect(array('action' => 'index'));
                            }
                            
                        
            }  else {

                        $this->Session->setFlash('Alumno NO guardado!!!', 'msgerror');
                        $this->redirect(array('action' => 'index'));
                    }


            }else
                {
                    $this->Session->setFlash('Alumno NO guardado!!!', 'msgerror');
                    $this->redirect(array('action' => 'index'));
                }
            

        }
        $this->set(compact('dcn', 'planes', 'gestiones'));
    }
    public function encuentralumno()
    {
        //debug($apellido);exit;
        $apellidoAlumno = $this->request->data['Alumnos']['apellido'];

        if (!empty($apellido))
        {
            $apellidoAlumno = $apellido;
        }


        $alumnos = $this->Alumno->find('all', array('recursive' => -1, 'conditions' => array('OR' => array(array('Alumno.ap_paterno like' => "%$apellidoAlumno%"),
                        array('Alumno.ap_materno like' => "%$apellidoAlumno%")))));
        //$alumnos = $this->Alumno->findAllByApMaternoOrApPaterno($apellidoAlumno);
        //debug($alumnos);

        $this->set(compact('alumnos'));
        //debug($alumnos);
    }

    public function ajaxdetalle($idAlumno = null)
    {
        $this->layout = 'ajax';
        $gestion = date("Y");
        $detalleAlumno = $this->Alumno->find('first', array('recursive' => 0, 'conditions' => array('Alumno.id' => $idAlumno)));
        $idAlumno = $detalleAlumno['Alumno']['id'];
        $alumnoParalelo = $this->AlumnosParalelo->find('first', array(
            'recursive' => 0,
            'conditions' => array('AlumnosParalelo.alumno_id' => $idAlumno, 'AlumnosParalelo.gestion' => $gestion),
            ));
        $idParalelo = $alumnoParalelo['Paralelo']['nivele_id'];
        $nivel = $this->Nivele->find('first', array('recursive' => -1, 'conditions' => array('id' => $idParalelo)));
        //debug($detalleAlumno);
        $this->set(compact('detalleAlumno', 'alumnoParalelo', 'nivel'));
    }

    public function vercalificaciones($idAlumno = null)
    {
        $gestion = date("Y");
        //$cantidad = $this->Parciales->find('count');
        $notasAlumno = $this->AlumnosParciale->find('all', array(
            'recursive' => 0,
            'conditions' => array('AlumnosParciale.alumno_id' => $idAlumno, 'AlumnosParciale.gestion' => $gestion),
            'group' => array('AlumnosParciale.materia_id', 'AlumnosParciale.ciclo_id'),
            'fields' => array(
                'AVG(AlumnosParciale.nota) as notaf',
                'Materia.nombre',
                'Ciclo.nombre',
                'Profesore.nombre',
                'Profesore.ap_paterno')));
        $this->set(compact('notasAlumno'));
    }

    public function inscribe()
    {
        $apellidoAlumno = $this->request->data['Alumnos']['apellido'];

        $alumnos = $this->Alumno->find('all', array('recursive' => -1, 'conditions' => array('OR' => array('ap_paterno like' => "%$apellidoAlumno%",
                        'ap_materno like' => "%$apellidoAlumno%"))));

        $this->set(compact('alumnos'));
        //debug($alumnos);
    }

    public function ajaxinscribe($idAlumno = null)
    {
        $this->layout = 'ajax';
        $gestion = date("Y");
        $detalleAlumno = $this->Alumno->find('first', array('recursive' => 0, 'conditions' => array('Alumno.id' => $idAlumno)));
        $idAlumno = $detalleAlumno['Alumno']['id'];
        /* $ultimoCurso = $this->AlumnosParciale->find('first', array(
        'recursive'=>-1,
        'conditions'=>array('AlumnosParciale.alumno_id'=>$idAlumno),
        'order'=>'AlumnosParciale.id DESC'
        )); */

        $ultimoCurso = $this->AlumnosParalelo->find('first', array(
            'recursive' => -1,
            'conditions' => array('AlumnosParalelo.alumno_id' => $idAlumno),
            'order' => 'AlumnosParalelo.id DESC'));
        //debug($ultimoCurso);
        $paralelo = $ultimoCurso['AlumnosParalelo']['paralelo_id'];

        $ulCurso = $this->Paralelo->find('first', array('recursive' => 0, 'conditions' => array('Paralelo.id' => $paralelo)));

        //debug($ulCurso);
        $this->set(compact('detalleAlumno', 'ulCurso'));
    }

    public function inscribeparalelo($idAlumno = null, $ordenNivel = null)
    {
        $dcn = $this->Nivele->find('all', array(
            'recursive' => -1,
            'fields' => array(
                'id',
                'nombre',
                'orden'),
            'conditions' => array('Nivele.orden >' => $ordenNivel)));
        $this->set(compact('dcn'));
    }

    public function ajaxparalelos($idAlumno = null, $ordenNivel = null)
    {
        $this->layout = 'ajax';
        $gestion = date("Y");
        $iOrden = ++$ordenNivel;
        $nivel = $this->Nivele->find('first', array('recursive' => -1, 'conditions' => array('Nivele.orden' => $iOrden, 'Nivele.gestion' => $gestion)));

        $idNivel = $nivel['Nivele']['id'];
        $nombreNivel = $nivel['Nivele']['nombre'];

        $dcp = $this->Paralelo->find('all', array(
            'recursive' => -1,
            'fields' => array('id', 'nombre'),
            'conditions' => array('nivele_id' => $idNivel)));

        if (!empty($this->request->data))
        {

            $this->request->data['AlumnosParalelo']['nivele_id'] = $idNivel;
            $this->request->data['AlumnosParalelo']['gestion'] = $gestion;

            $paralelos = $this->Paralelo->find('first', array('conditions' => array('Paralelo.id' => $this->request->data['AlumnosParalelo']['paralelo_id'])));

            $curso = $nivel['Nivele']['nombre'];
            $paralelo = $paralelos['Paralelo']['nombre'];

            if ($this->AlumnosParalelo->save($this->request->data))
            {

                $this->Session->setFlash("Alumno Inscrito en $curso '$paralelo'!!!", 'msgbueno');
                $this->redirect(array('controller' => 'Principal', 'action' => 'admin'));
            }
        }

        $this->set(compact('dcp', 'idAlumno', 'nombreNivel'));
        //debug($paralelo);
    }

    public function editar($idAlumno = null)
    {
        $this->Alumno->id = $idAlumno;
        if (!$this->Alumno->exists())
        {
            throw new NotFoundException(__('Invalid user'));
        }
        if ($this->request->is('post') || $this->request->is('put'))
        {
            if ($this->Alumno->save($this->request->data))
            {
                $this->Session->setFlash('Alumno Editado', 'msgbueno');
                $this->redirect(array('controller' => 'Principal', 'action' => 'admin'));
            }
            else
            {
                $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
            }
        }
        else
        {
            $this->request->data = $this->Alumno->read(null, $idAlumno);
        }
        //$groups = $this->User->Group->find('list');
        //$this->set(compact('groups'));
    }

    public function ajaxparalelosinscribe($idCurso = null)
    {
        $this->layout = 'ajax';
        $dcp = $this->Paralelo->find('all', array('recursive' => -1, 'conditions' => array('nivele_id' => $idCurso)));
        $this->set(compact('dcp'));
    }

    public function pagar($idAlumno = null)
    {
        $this->layout = 'ajax';
        $gestion = date('Y');

        $planes = $this->AlumnosPlanespago->find('list', array(
            'conditions' => array('AlumnosPlanespago.alumno_id' => $idAlumno, 'AlumnosPlanespago.gestion' => $gestion),
            'fields' => array('AlumnosPlanespago.planespago_id'),
            'recursive' => -1));

        $fecha = '%' . date('Y') . '%';

        $alumno = $this->Alumno->find('first', array('recursive' => -1, 'conditions' => array('Alumno.id' => $idAlumno)));

        $yapagados = $this->AlumnosPago->find('list', array('conditions' => array('AlumnosPago.alumno_id' => $idAlumno, 'AlumnosPago.created LIKE' => $fecha),
                'fields' => array('AlumnosPago.pago_id')));

        $pagos = $this->Pago->find('all', array('conditions' => array('Pago.planespago_id' => $planes), 'order' => array('Pago.nombre ASC')));


        $c = 0;
        foreach ($pagos as $pago)
        {
            $a = 0;
            foreach ($yapagados as $pagado)
            {
                if ($pago['Pago']['id'] == $pagado)
                {
                    $pagos[$c]['Pago']['pagado'] = 1;
                    $a = 1;
                }
            }
            if (!$a)
            {
                $pagos[$c]['Pago']['pagado'] = 0;
            }
            $c++;
        }
        $nombreAlumno = $alumno['Alumno']['ap_paterno'].' '.$alumno['Alumno']['ap_materno'].' '.$alumno['Alumno']['nombre'];
        $this->set(compact('planes', 'pagos', 'idAlumno', 'alumno', 'nombreAlumno'));
    }

    public function pagarpago($idAlumno = null, $idPago = null, $monto = null)
    {
        $this->request->data['AlumnosPago']['alumno_id'] = $idAlumno;
        $this->request->data['AlumnosPago']['pago_id'] = $idPago;
        $this->request->data['AlumnosPago']['monto'] = $monto;
        $this->request->data['AlumnosPago']['fecha'] = date('Y-m-d');

        $this->AlumnosPago->create();
        if ($this->AlumnosPago->save($this->request->data))
        {
            $this->Session->setFlash(__('El pago fue registrado'), 'msgbueno');
            $this->redirect(array('action' => 'encuentralumno'));
        }
        else
        {
            $this->Session->setFlash(__('El plan de pago no pudo guardarse. Por favor, intente nuevamente.'), 'msgerror');
        }
    }
    public function editarplanalumno($id = null, $idAlumno = null)
    {
        $this->layout = 'ajax';
        $this->AlumnosPlanespago->id = $id;
        if (!$this->AlumnosPlanespago->exists())
        {
            throw new NotFoundException(__('Registro de Plan invalido'));
            $this->redirect(array('action' => 'verplan', $idAlumno));
        }
        if (!empty($this->request->data))
        {
            if ($this->AlumnosPlanespago->save($this->request->data))
            {
                $this->Session->setFlash(__('El pago fue editado'), 'msgbueno');
                $this->redirect(array('action' => 'verplan', $idAlumno));
            }
            else
            {
                $this->Session->setFlash(__('El plan no pudo guardarse. Por favor, intente nuevamente.'), 'msgerror');
                $this->redirect(array('action' => 'verplan', $idAlumno));
            }
        }
        else
        {
            $this->request->data = $this->AlumnosPlanespago->read(null, $id);
            //debug($this->request->data);exit;
        }
        $planespagos = $this->Pago->Planespago->find('list', array('fields' => array('Planespago.id', 'Planespago.nombre')));
        $this->set(compact('planespagos'));
    }
    public function alumnoplan($idAlumno = null)
    {
        //$this->layout='ajax';
        $alumno = $this->Alumno->find('first', array('conditions' => array('Alumno.id' => $idAlumno), 'recursive' => -1));
        $nombre = $alumno['Alumno']['ap_paterno'] . ' ' . $alumno['Alumno']['ap_materno'] . ' ' . $alumno['Alumno']['nombre'];
        if (!empty($this->request->data))
        {
            //debug($this->request->data);exit;
            $this->request->data['AlumnosPlanespago']['alumno_id'] = $idAlumno;
            if ($this->AlumnosPlanespago->save($this->request->data))
            {
                $this->Session->setFlash(__('Se registro el plan del alumno' . $nombre), 'msgbueno');
                $this->redirect(array('action' => 'index'));
            }
            else
            {
                $this->Session->setFlash(__('El plan no pudo guardarse. Por favor, intente nuevamente.'));
            }
        }
        else
        {
            $planespagos = $this->Planespago->find('list', array('fields' => array('Planespago.id', 'Planespago.nombre')));
            $this->set(compact('planespagos', 'nombre'));
        }


    }
    public function verplan($idAlumno = null)
    {
        $planes = $this->AlumnosPlanespago->find('all', array('conditions' => array('AlumnosPlanespago.alumno_id' => $idAlumno)));
        //debug($planes);exit;
        if (empty($planes))
        {
            $this->Session->setFlash(__('no se suscribio a ningun plan'), 'msgalert');
            $this->redirect(array('action' => 'alumnoplan', $idAlumno));
        }
        $this->set(compact('planes', 'idAlumno'));
    }
    public function ajaxanadeplan($idAlumno = null)
    {
        $this->layout = 'ajax';
        //debug($idAlumno);exit;
        if (!empty($this->request->data))
        {


            if ($this->AlumnosPlanespago->save($this->request->data))
            {

                $this->Session->setFlash(__('plan suscrito al alumno'), 'msgbueno');
                $this->redirect(array('action' => 'encuentralumno'));
            }
            else
            {
                $this->Session->setFlash(__('no se pudo suscribir el plan al alumno'), 'msgalert');
                $this->redirect(array('action' => 'encuentralumno'));
            }
        }

        $planespagos = $this->Planespago->find('list', array('fields' => array('Planespago.id', 'Planespago.nombre')));
        $this->set(compact('planespagos', 'nombre'));
        $this->set(compact('planespagos', 'idAlumno'));

    }
    public function vernotas($materiaId = null, $idParalelo = null, $gestion = null)
    {

        $tiposParciales = $this->Tiposparciale->find('all', array('recursive' => 1));

        $ciclos = $this->Ciclo->find('all', array(
            'conditions' => array('Ciclo.gestion' => $gestion),
            'order' => array('Ciclo.orden ASC'),
            'recursive' => -1));

        $columnas = $this->Parciale->find('count') + 1;

        $materia = $this->Materia->find('first', array('recursive' => -1, 'conditions' => array('Materia.id' => $materiaId)));

        $alumnos = $this->AlumnosParalelo->find('all', array('recursive' => 0, 'conditions' => array('AlumnosParalelo.paralelo_id' => $idParalelo)));

        $notas = $this->AlumnosParciale->find('all', array('conditions' => array('AlumnosParciale.materia_id' => $materiaId, 'AlumnosParciale.gestion' => $gestion)));

        $this->set(compact('gestion', 'notas', 'tiposParciales', 'materiaId', 'ciclos', 'columnas', 'materia', 'alumnos'));
    }

    public function ajaxcambiapass($idAlumno = null)
    {
        $this->layout = 'ajax';
        $alumno = $this->Alumno->find('first', array('recursive' => -1, 'conditions' => array('Alumno.id' => $idAlumno)));
        $this->set(compact('alumno'));
    }

    public function ajaxcambiaplan($idAlumno = null)
    {
        $this->layout = "ajax";
        $gestion = date("Y");

        $alumno = $this->Alumno->find('first', array('recursive' => -1, 'conditions' => array('Alumno.id' => $idAlumno)));

        $alumnoPlan = $this->AlumnosPlanespago->find('first', array('recursive' => 0, 'conditions' => array('AlumnosPlanespago.alumno_id' => $idAlumno,
                    'AlumnosPlanespago.gestion' => $gestion)));

        $planespagos = $this->Planespago->find('list', array('fields' => array('Planespago.id', 'Planespago.nombre')));

        if (!empty($this->request->data))
        {
            
            $gestion = $this->request->data['Alumno']['gestion'];
            $idAlumno = $this->request->data['Alumno']['alumno_id'];
            $plan = $this->request->data['Alumno']['planespago_id'];
            $observaciones = $this->request->data['Alumno']['observaciones'];

            $planAlumno = $this->AlumnosPlanespago->find('first', array('recursive' => -1, 'conditions' => array(
                    'AlumnosPlanespago.gestion' => $gestion,
                    'AlumnosPlanespago.alumno_id' => $idAlumno,
                    )));
            //debug($planAlumno);
            if ($planAlumno)
            {
                $idPlanAlumno = $planAlumno['AlumnosPlanespago']['id'];
                $data = array('id' => $idPlanAlumno, 'planespago_id' => $plan);
                if ($this->AlumnosPlanespago->save($data))
                {
                    $this->Session->setFlash('Plan cambiado', 'msgbueno');
                    $this->redirect(array('controller' => 'Principal', 'action' => 'admin'));
                }
            }
            else
            {

                $this->request->data['AlumnosPlanespago']['alumno_id'] = $idAlumno;
                $this->request->data['AlumnosPlanespago']['planespago_id'] = $plan;
                $this->request->data['AlumnosPlanespago']['gestion'] = $gestion;
                $this->request->data['AlumnosPlanespago']['observaciones'] = $observaciones;
                //debug($this->request->data);exit;
                if ($this->AlumnosPlanespago->save($this->request->data['AlumnosPlanespago']))
                {
                    $this->Session->setFlash('Alumno registrado al Plan', 'msgbueno');
                    $this->redirect(array('controller' => 'Principal', 'action' => 'admin'));
                }
                else
                {
                    $this->Session->setFlash('Plan cambiado', 'msgerror');
                    $this->redirect(array('controller' => 'Principal', 'action' => 'admin'));
                }

            }
            //debug($planAlumno);
        }
        else
        {

        }
        $this->set(compact('alumno', 'alumnoPlan', 'planespagos'));
        //debug($alumnoPlan);
    }

    public function cancelarpago()
    {
        
        $datos = $this->request->data;
       
        $idAlumno = $this->request->data['Alumnos']['idAlumno'];
        $montoTotal = $this->request->data['Alumnos']['total'];
        $cambio = $this->request->data['Alumnos']['cambio'];
        $nit = $this->request->data['Alumnos']['nit'];
        $nombre = $this->request->data['Alumnos']['nombre'];

        
        $pagosIds = array();
        $idPagos=array();
        $c = 0;
       

        foreach($this->request->data['AlumnosPago'] as $data){
            if($data['monto']!= 'N'){
                $this->AlumnosPago->create();
              if ($this->AlumnosPago->save($data))
                {
                    //echo 'guardo';
                    $pagosIds[$c] = $this->AlumnosPago->getLastInsertID();
                    $idPagos[$c] = $data['pago_id'];
                    $c++;
                }    
            }
        }

        //datos de prueba para la factura
        $datosFactura = $this->Parametrosfactura->find('first');
       
        $factura = $this->Factura->find('first', array('order'=>array('Factura.id DESC')));
        
        if(empty($factura)){
            $numero = 1;
            
        }else
           $numero = $factura['Factura']['nro'] + 1;
        
        $idFactura = $this->Fechasconvert->doNumeroFactura($numero);
      
       $nitColegio= $datosFactura['Parametrosfactura']['nit']; 
        $autoriza = $datosFactura['Parametrosfactura']['numero_autorizacion'];
        $nitcliente = $nit;
        $nueva_fecha = $this->Fechasconvert->doFechaPass(date('d/m/Y'));
     
        $rtotal = $montoTotal;
        $llave = $datosFactura['Parametrosfactura']['llave']; 
        //'9rCB7Sv4X29d)5k7N%3ab89p-3(5[A';

        //$this->Codigocontrol->CodigoControl('29040011007', '1503', '4189179011', '20070702', '2500', '9rCB7Sv4X29d)5k7N%3ab89p-3(5[A');
        $this->Codigocontrol->CodigoControl($autoriza, $idFactura, $nitcliente, $nueva_fecha, $rtotal, $llave);
        $codigo = $this->Codigocontrol->generar();
        $this->request->data['Factura']['numero'] = $idFactura;
        $this->request->data['Factura']['nro'] = $numero;
        $this->request->data['Factura']['codigocontrol'] = $codigo;
        $this->request->data['Factura']['cliente'] = $nombre;
        $this->request->data['Factura']['nit'] = $nit;
        $this->request->data['Factura']['importetotal'] = $montoTotal;
        $this->request->data['Factura']['pago'] = $cambio;
        $this->request->data['Factura']['numero'] = $idFactura;
        $this->Factura->create();
        
        if($this->Factura->save($this->request->data['Factura'])){
            
            foreach($pagosIds as $idpago){
                $data = array('id' => $idpago, 'factura' =>$idFactura );
                // This will update AlumnosPago with id 10
                $this->AlumnosPago->save($data);
                
            }
            $c=0;
            
            foreach($datos['AlumnosPago'] as $dato){
                
                $id= $dato['pago_id'];
               $detallePagos = $this->Pago->find('first', 
                                    array(
                                        'conditions' => array('Pago.id' => $id)));
               
               
                $datos['AlumnosPago'][$c]['nombrepago'] = $detallePagos['Pago']['nombre'];
                $c++;
            }
            $total = number_format($datos['Alumnos']['total'], 2, '.', ',');
            $monto = split('\.', $total);
            $decimales = $monto['1'];
            $literal = $this->Montoliteral->getMontoliteral($datos['Alumnos']['total']);
            $this->Session->setFlash('Factura guardada', 'msgbueno');
            $this->set(compact('datos', 'nitColegio', 'idFactura','autoriza','codigo','literal','decimales'));
        }
    }

}
